import 'package:base_plugin/base_plugin.dart';
import 'package:finance_app/generated/a.dart';
import 'package:finance_app/generated/l10n.dart';
import 'package:finance_app/src/common/app_colors.dart';
import 'package:finance_app/src/common/app_spaces.dart';
import 'package:finance_app/src/utils/cash_utils.dart';
import 'package:finance_app/src/utils/language_utils.dart';
import 'package:finance_app/src/widgets/common/tag_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:intl/intl.dart';

class CreditNoteItem extends StatelessWidget {
  final VoidCallback onTap;
  final String tag;
  final String name;
  final String time;
  final num amount;
  final String status;
  final String billNumber;
  final String currency;

  CreditNoteItem(
      {Key key,
      this.onTap,
      this.tag,
      this.status,
      this.name,
      this.billNumber,
      this.time,
      this.currency,
      this.amount})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return PressedOpacityButton(
      onPressed: onTap,
      padding: EdgeInsets.symmetric(vertical: getDp(21)),
      color: Colors.white,
      border:
          Border(bottom: BorderSide(color: aceGrayColor, width: getDp(0.5))),
      // boxShadow: [
      //   BoxShadow(
      //     color: Colors.black.withOpacity(0.25),
      //     offset: Offset(0, 4),
      //     blurRadius: getDp(8),
      //     spreadRadius: getDp(-5),
      //   ),
      // ],
      child: Row(
        children: [
          Expanded(
            flex: 80,
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Container(
                  alignment: Alignment.center,
                  child: SvgPicture.asset(getImage(), width: 14, height: 17),
                ),
                SizedBox(
                  height: getDp(4),
                ),
                Text(
                  LanguageUtils.translateTag(tag),
                  textAlign: TextAlign.center,
                  style: TextStyle(
                      color: aceDarkGrayColor,
                      fontSize: getSp(12),
                      height: 14 / 12),
                ),
              ],
            ),
          ),
          Expanded(
              flex: 170,
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    name,
                    style: TextStyle(
                      fontWeight: FontWeight.bold,
                      fontSize: getSp(16),
                      height: 14 / 16,
                    ),
                  ),
                  AppSpaces.h4,
                  Text(
                    '${tag.replaceAll('\n', '')} No: $billNumber',
                    style: TextStyle(
                      fontWeight: FontWeight.w400,
                      fontSize: getSp(14),
                    ),
                  ),
                  AppSpaces.h4,
                  Text(
                    '${S.current.issue_date}: $time',
                    style: TextStyle(
                      fontWeight: FontWeight.w400,
                      fontSize: getSp(14),
                    ),
                  ),
                ],
              )),
          Expanded(
            flex: 135,
            child: Padding(
              padding: EdgeInsets.only(right: getDp(19)),
              child: Column(
                mainAxisSize: MainAxisSize.min,
                crossAxisAlignment: CrossAxisAlignment.end,
                children: [
                  if (status != null)
                    Container(
                      margin: EdgeInsets.only(
                        bottom: getDp(10),
                      ),
                      child: NormalRedTagWidget(
                        content: status,
                      ),
                    ),
                  Text.rich(
                    TextSpan(
                        text: CashUtils.operation(amount),
                        style: TextStyle(
                            fontSize: getSp(16),
                            color: CashUtils.getColor(amount),
                            fontWeight: FontWeight.bold,
                            height: 14 / 12,
                            fontFamily: "DinRoundPro"),
                        children: [
                          TextSpan(
                              text:
                                  ' $currency ${CashUtils.ignoreFormatCashAmount(amount)}',
                              style: TextStyle(
                                color: aceBlackColor,
                                fontSize: getSp(16),
                                fontWeight: FontWeight.w700,
                                height: 14 / 16,
                              )),
                        ]),
                  ),
                ],
              ),
            ),
          ),
        ],
      ),
    );
  }

  String getImage() {
    switch (tag) {
      case 'Invoice':
        return A.assetsImagesDashboardInvoice;
      case 'Bill':
        return A.assetsImagesDashboardBill;
      case 'PO':
        return A.assetsImagesDashboardPO;
      case 'purchase_order':
        return A.assetsImagesDashboardPO;
      case 'Money-In':
        return A.assetsImagesDashboardCashIn;
      case 'Money-Out':
        return A.assetsImagesDashboardCash_Out;
      case 'Expense':
        return A.assetsImagesDashboardExpense;
      case 'Quotation':
        return A.assetsImagesDashboardAddQuotation;
      case 'Credit \nNote':
        return A.assetsImagesDashboardAddCreditNote;
      case 'Debit \nNote':
        return A.assetsImagesDashboardAddDebitNote;
    }
    return '';
  }
}
